package com.example.lcode.greedy;

/**
 * @version 1.0
 * @author: ChuJie_Lin
 * @since: 2021-09-23 12:28
 **/
public class Question11 {

    public int maxArea(int[] height) {
        if (height == null || height.length <= 1) {
            return 0;
        }
        int leftIndex = 0;
        int rightIndex = height.length - 1;
        int res = 0;
        while (leftIndex < rightIndex) {
            int distance = rightIndex - leftIndex;
            int temp = distance * Math.min(height[leftIndex], height[rightIndex]);
            if (temp > res) {
                res = temp;
            }
            if (height[leftIndex] > height[rightIndex]) {
                rightIndex --;
            } else {
                leftIndex ++;
            }
        }
        return res;
    }

}
